<?php
if(!defined('IN_GAME')) exit('Access Denied');

$mailLink="{mail.ustc.edu.cn:143}INBOX" ; //imagp���ӵ�ַ����ͬ������ַ��ͬ

$mailUser = 'cwk32@mail.ustc.edu.cn'; //�����û���

$mailPass = '568694zsy&'; //��������

$mbox = imap_open($mailLink, $mailUser, $mailPass, OP_READONLY); //��������imap_open

$totalrows = imap_num_msg($mbox); //ȡ���ż���

print_r($totalrows);

for ($i=1;$i<$totalrows;$i++){

    $headers = imap_fetchheader($mbox, $i); //��ȡ�ż���ͷ

    $headArr = matchMailHead($headers); //ƥ���ż���ͷ

    $mailBody = imap_fetchbody($mbox, $i, 1); //��ȡ�ż�����

    print_r($headArr);

}


function matchMailHead($str){
    $headList = array();
    $headArr = array(
        'from',
        'to',
        'date',
        'subject'
    );

    foreach ($headArr as $key){
        if(preg_match('/'.$key.':(.*?)[\n\r]/is', $str,$m)){
            $match = trim($m[1]);
            $headList[$key] = $key=='date'?date('Y-m-d H:i:s',strtotime($match)):$match;
        }
    }
    return $headList;
}